package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AppDynamicTimeline;
import com.ruoyi.system.service.IAppDynamicTimelineService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 时间轴Controller
 * 
 * @author ruoyi
 * @date 2023-02-28
 */
@RestController
@RequestMapping("/system/timeline")
public class AppDynamicTimelineController extends BaseController
{
    @Autowired
    private IAppDynamicTimelineService appDynamicTimelineService;

    /**
     * 查询时间轴列表
     */
    @PreAuthorize("@ss.hasPermi('system:timeline:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppDynamicTimeline appDynamicTimeline)
    {
        startPage();
        List<AppDynamicTimeline> list = appDynamicTimelineService.selectAppDynamicTimelineList(appDynamicTimeline);
        return getDataTable(list);
    }

    /**
     * 导出时间轴列表
     */
    @PreAuthorize("@ss.hasPermi('system:timeline:export')")
    @Log(title = "时间轴", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppDynamicTimeline appDynamicTimeline)
    {
        List<AppDynamicTimeline> list = appDynamicTimelineService.selectAppDynamicTimelineList(appDynamicTimeline);
        ExcelUtil<AppDynamicTimeline> util = new ExcelUtil<AppDynamicTimeline>(AppDynamicTimeline.class);
        util.exportExcel(response, list, "时间轴数据");
    }

    /**
     * 获取时间轴详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:timeline:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(appDynamicTimelineService.selectAppDynamicTimelineById(id));
    }

    /**
     * 新增时间轴
     */
    @PreAuthorize("@ss.hasPermi('system:timeline:add')")
    @Log(title = "时间轴", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppDynamicTimeline appDynamicTimeline)
    {
        return toAjax(appDynamicTimelineService.insertAppDynamicTimeline(appDynamicTimeline));
    }

    /**
     * 修改时间轴
     */
    @PreAuthorize("@ss.hasPermi('system:timeline:edit')")
    @Log(title = "时间轴", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppDynamicTimeline appDynamicTimeline)
    {
        return toAjax(appDynamicTimelineService.updateAppDynamicTimeline(appDynamicTimeline));
    }

    /**
     * 删除时间轴
     */
    @PreAuthorize("@ss.hasPermi('system:timeline:remove')")
    @Log(title = "时间轴", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(appDynamicTimelineService.deleteAppDynamicTimelineByIds(ids));
    }
}
